#include "simulation.h"

simulation::simulation(vector<sph_vector> pos)
{
	this->pos = pos;
	maxIter = 100000; // default max iterations
	weight = 3; // default weight
	n = pos.size();
}

void simulation::set_maxIter(double iter)
{
	maxIter = iter;
}

vector<sph_vector> simulation::get_pos()
{
	return pos;
}


void simulation::run()
{
	int i,j,k;
	sph_vector forceVector[n]; // initialized with the null constructor to be zero vectors
	sph_vector temp;
	sph_vector nullVector = sph_vector(0,0,0);

	// loop through the number of maxIterations
	for(i=0; i < maxIter; i++)
	{
		// zero out the forceVectors
		for(j = 0; j < n; j++)
		{
			forceVector[j] = nullVector;
		}

		// compute the force vectors
		for(j = 0; j < n; j++)
		{
			for(k = j+1; k < n; k++)
			{
				temp = force_vector(pos[j],pos[k],weight); // force on j from k
				forceVector[j] = forceVector[j] + temp; 
				forceVector[k] = forceVector[k] + temp*(-1); // force on k is negative of force on j from k
			}
		}
		// move the vectors
		for(j = 0; j < n; j++)
		{
			// by specificing a distance 1 with direction vector norm != 1 it is equivalent to moving
			// the distance of the norm
			push_vector(pos[j], forceVector[j],1);
			// back_to_sphere(pos[j]);
		}
		if(i % 20 == 0)
		{
			cout << i << endl;
			for(j = 0; j < n; j++)
			{
				back_to_sphere(pos[j]);
			}
		}
		// can check for an equilibrium here
	}
	for(i = 0; i < n; i++)
	{
		back_to_sphere(pos[i]);
	}

}

